import Vue from 'vue';
import Router from 'vue-router';
import store from '../store/store'
import * as types from '../store/types'
import * as util from '../assets/util.js';
Vue.use(Router);
let baseRoute = [{
    path: '/login',
    name: '登录',
    component: (resolve) => require(['../components/page/Login.vue'], resolve),
},{
    path: '/403',
    name: '无权访问',
    component: (resolve) => require(['../components/page/403.vue'], resolve)
}, {
    path: '/404',
    name: '找不到页面',
    component: (resolve) => require(['../components/page/404.vue'], resolve)
},
{
    path: '/guestVisit',
    name: 'guestVisit',
    component: (resolve) => require(['../components/photo/GuestVisit.vue'], resolve)
},
{
    path: '/guestVisit2',
    name: 'guestVisit2',
    component: (resolve) => require(['../components/mobile/GuestVisit2.vue'], resolve)
},
];
let router = new Router({
    //去掉地址中的哈希#
    mode:"history",
    routes: baseRoute
});

router.beforeEach((to, from, next) => {
    if(to.path == '/login' && util.local('token') != undefined && util.local('token') != ''){
        next('/')
    }else {
        next();
    }
});
router.afterEach((to, from) => {
    // if(from.path.indexOf("login")>0){
    //     //     location.reload();
    //     // }
    // if(to.path.indexOf("login")>0){
    //     if(util.session("refreshRouter")){
    //         util.session("refreshRouter","");
    //         location.reload(true);
    //     }
    // }
})

export default router;
// export default new Router({
//     routes: [
//         {
//             path: '/',
//             redirect: '/Home'
//         },
//         {
//             path: '/',
//             component: resolve => require(['../components/common/Home.vue'], resolve),
//             meta: {title: '自述文件'},
//             children: [
//                 {
//                     path: '/Home',
//                     component: resolve => require(['../components/page/Dashboard.vue'], resolve),
//                     meta: {title: '系统首页', permission: true}
//                 },
//                 {
//                     // 权限页面
//                     path: '/RoleManage',
//                     component: resolve => require(['../components/page/RoleManage.vue'], resolve),
//                     meta: {title: '角色管理', permission: true}
//                 },
//                 {
//                     path: '/UserManage',
//                     component: resolve => require(['../components/page/UserManage.vue'], resolve),
//                     meta: {title: '用户管理', permission: true}
//                 },
//                 {
//                     path: '/SystemLog',
//                     component: resolve => require(['../components/page//SystemLog.vue'], resolve),
//                     meta: {title: '系统日志', permission: true}
//                 },
//                 {
//                     // 权限页面
//                     path: '/Chassis',
//                     component: resolve => require(['../components/page/DrawChassis.vue'], resolve),
//                     meta: {title: '绘制机架', permission: true}
//                 }
//             ]
//         },
//         {
//             path: '/login',
//             component: resolve => require(['../components/page/Login.vue'], resolve)
//         },
//         {
//             path: '/404',
//             component: resolve => require(['../components/page/404.vue'], resolve)
//         },
//         {
//             path: '/403',
//             component: resolve => require(['../components/page/403.vue'], resolve)
//         },
//         {
//             path: '*',
//             redirect: '/404'
//         }
//     ]
// })
// // 页面刷新时，重新赋值token,用户名也在界面上展示
// if (window.localStorage.getItem('token')) {
//     var tokenInfo = {
//         token:window.localStorage.getItem('token'),
//         createTime:window.localStorage.getItem('createTime'),
//         expireTime:window.localStorage.getItem('expireTime'),
//         refreshTime:window.localStorage.getItem('refreshTime'),
//     }
//     store.commit(types.LOGIN, tokenInfo);
// }
// if (window.localStorage.getItem('userName')) {
//     store.commit(types.USERNAME, window.localStorage.getItem('userName'));
// }
// if (window.localStorage.getItem('auth')) {
//     store.commit(types.AUTH, window.localStorage.getItem('auth'));
// }
// if (window.localStorage.getItem('permission')) {
//     store.commit(types.PERMISSION, window.localStorage.getItem('permission'));
// }
